<?php

class News_model extends CI_Model {
	
	function __construct(){
		parent::__construct();
	} //EndConstructor

	public function get_news($ficha = FALSE){
		$DB1 = $this->load->database('local', TRUE);
		if($ficha === FALSE){
			$query = $DB1->get('tbnews');
			//$sql = "SELECT * FROM tbnews";
			//$query = $DB1->query($sql);
				
			return $query->result_array();
		}
		$query = $DB1->get_where('tbnews', array('ficha' => $ficha));
		//$db1 = $this->load->database("local");
		//$sql = "SELECT * FROM tbnews WHERE ? = ?";
		//$query = $DB1->query($sql, array('ficha', $ficha));
		return $query->row_array();
	} //EndFunction(get_news)

	public function set_news(){
		$this->load->helper('url');

		$slug = url_title($this->input->post('title'), 'dash', TRUE);
		$data = array(
				'titulo' => $this->input->post('title'),
				'ficha' => $slug,
				'texto' => $this->input->post('text')
		);
		return $this->db->insert('tbnews', $data);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */